package com.dragonwu;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


/**
 * @author Dragon Wu
 * @since 2022-10-17 13:35
 **/
@Component
public class ChatServerStarter {

    @Autowired
    @Qualifier("serverBootstrap")
    private ServerBootstrap serverBootstrap;

    private Channel channel;

    public void start() throws Exception{
        System.out.println("netty启动");
        channel=serverBootstrap.bind(8888).sync()
                .channel().closeFuture().sync().channel();
    }

    public void close(){
        channel.close();
        channel.parent().close();
    }
}
